import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:sainbainu/view/message/comment/index.dart';
import 'package:sainbainu/view/message/followed/index.dart';
import 'package:sainbainu/view/message/like_collect/index.dart';
import 'package:sainbainu/common/widgets/widget.dart';

import 'index.dart';

class MessagePage extends GetView<MessageController> {
  const MessagePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MessageController>(
      builder: (_) {
        return Scaffold(
          appBar: CustomAppBarWidget(title: _buildTabBar()),
          body: TabBarView(
            controller: _.state.tabController,
            children: const [
              KeepAliveWrapperWidget(child: LikeCollectPage()),
              KeepAliveWrapperWidget(child: FollowedPage()),
              KeepAliveWrapperWidget(child: CommentPage()),
            ],
          ),
        );
      },
    );
  }

  Widget _buildTabBar() {
    return GetBuilder<MessageController>(
      id: 'tabs',
      builder: (_) => TabBar(
        controller: _.state.tabController,
        isScrollable: true,
        tabAlignment: TabAlignment.start,
        dividerHeight: 0,
        tabs: _.state.tabsList.map((item) {
          return Tab(
            child: Row(
              children: [
                Text(item['label']),
                Badge(
                  label: Text(item['badge']),
                  isLabelVisible: item['showBadge'],
                ),
              ],
            ),
          );
        }).toList(),
      ),
    );
  }
}
